namespace GoPlay.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class InitialDomainModel : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.Teams",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false, maxLength: 100),
                        UserId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.UserProfile", t => t.UserId, cascadeDelete: true)
                .Index(t => t.UserId);
            
            CreateTable(
                "dbo.Games",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        TeamId = c.Int(nullable: false),
                        Date = c.String(nullable: false),
                        Time = c.String(nullable: false),
                        GF = c.String(),
                        GA = c.String(),
                        Decision = c.String(),
                        UserId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.Id, t.TeamId })
                .ForeignKey("dbo.UserProfile", t => t.UserId, cascadeDelete: true)
                .ForeignKey("dbo.Teams", t => t.TeamId)
                .Index(t => t.UserId)
                .Index(t => t.TeamId);
            
            CreateTable(
                "dbo.Players",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        TeamId = c.Int(nullable: false),
                        Goals = c.Int(nullable: false),
                        Assists = c.Int(nullable: false),
                        Points = c.Int(nullable: false),
                        UserId = c.Int(nullable: false),
                        ContactId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.Id, t.TeamId })
                .ForeignKey("dbo.UserProfile", t => t.UserId, cascadeDelete: true)
                .ForeignKey("dbo.Teams", t => t.TeamId)
                .ForeignKey("dbo.Contacts", t => t.ContactId)
                .Index(t => t.UserId)
                .Index(t => t.TeamId)
                .Index(t => t.ContactId);
            
            CreateTable(
                "dbo.Contacts",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false, maxLength: 100),
                        Nickname = c.String(maxLength: 100),
                        Email = c.String(maxLength: 100),
                        Phone = c.String(maxLength: 100),
                        UserId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.UserProfile", t => t.UserId, cascadeDelete: true)
                .Index(t => t.UserId);
            
        }
        
        public override void Down()
        {
            DropIndex("dbo.Contacts", new[] { "UserId" });
            DropIndex("dbo.Players", new[] { "ContactId" });
            DropIndex("dbo.Players", new[] { "TeamId" });
            DropIndex("dbo.Players", new[] { "UserId" });
            DropIndex("dbo.Games", new[] { "TeamId" });
            DropIndex("dbo.Games", new[] { "UserId" });
            DropIndex("dbo.Teams", new[] { "UserId" });
            DropForeignKey("dbo.Contacts", "UserId", "dbo.UserProfile");
            DropForeignKey("dbo.Players", "ContactId", "dbo.Contacts");
            DropForeignKey("dbo.Players", "TeamId", "dbo.Teams");
            DropForeignKey("dbo.Players", "UserId", "dbo.UserProfile");
            DropForeignKey("dbo.Games", "TeamId", "dbo.Teams");
            DropForeignKey("dbo.Games", "UserId", "dbo.UserProfile");
            DropForeignKey("dbo.Teams", "UserId", "dbo.UserProfile");
            DropTable("dbo.Contacts");
            DropTable("dbo.Players");
            DropTable("dbo.Games");
            DropTable("dbo.Teams");
        }
    }
}
